/*******************************************************************************
 * The MOSES project, model based software engineering of networked embedded systems.
 * 
 * Copyright (C) 2010-2013, University of Applied Sciences Wildau,
 * Telematics Research Group, http://www.tm.th-wildau.de/research-group
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses>.
 * 
 * Contributors:
 *     University of Applied Sciences Wildau - initial API and implementation
 * 
 * If you are interested in a commercial license please contact us via 
 * e-mail: ralf.vandenhouten@th-wildau.de.
 ******************************************************************************/
package de.thwildau.tm.moses.abnf.generator.model.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.eclipse.core.runtime.Assert;

import de.thwildau.tm.moses.abnf.abnf.Rule;
import de.thwildau.tm.moses.abnf.generator.model.AbnfElementField;
import de.thwildau.tm.moses.abnf.generator.model.AbnfRuleClass;
 

/**
 * This class hold the model of all elements within an ABNF rule.
 *
 * @author Thomas Kistel
 * @version $Revision$
 */
public class AbnfRuleClassImpl implements AbnfRuleClass {

    private Rule rule;
    private String className;
    private List<AbnfElementField> elements = new ArrayList<>();
    private AbnfRuleClass superClass;
    
    /* package */ AbnfRuleClassImpl(Rule rule, String className) {
        Assert.isNotNull(rule);
        Assert.isNotNull(className);
        this.rule = rule;
        this.className = className;
    }
    
    
    public Rule getRule() {
        return rule;
    }
    
    /* (non-Javadoc)
     * @see de.thwildau.tm.moses.abnf.generator.model.IAbnfRuleClass#getClassName()
     */
    @Override
    public String getClassName() {
        return className;
    }
    
    
    public void setSuperClass(AbnfRuleClass superClass) {
        this.superClass = superClass;
    }
    
    /* (non-Javadoc)
     * @see de.thwildau.tm.moses.abnf.generator.model.IAbnfRuleClass#getSuperClass()
     */
    @Override
    public AbnfRuleClass getSuperClass() {
        return superClass;
    }

    /**
     * @see List#add(Object)
     */
    public boolean add(AbnfElementField e) {
        // set the cross-reference
        ((AbnfElementFieldImpl)e).setAbnfRuleClass(this);
        return elements.add(e);
    }
    
    /* (non-Javadoc)
     * @see de.thwildau.tm.moses.abnf.generator.model.IAbnfRuleClass#getElements()
     */
    @Override
    public List<AbnfElementField> getElements() {
        return Collections.unmodifiableList(elements);
    }
}
